/*
 * This file is a part of the SchemaSpy project (http://schemaspy.sourceforge.net).
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 John Currier
 *
 * SchemaSpy is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * SchemaSpy is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package com.qp.basics.estivate.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * A {@link HashMap} implementation that uses {@link String}s as its keys where
 * the keys are treated without regard to case. That is,
 * <code>get("MyTableName")</code> will return the same object as
 * <code>get("MYTABLENAME")</code>.
 *
 * @author John Currier
 */
public class CaseInsensitiveMap<V> extends HashMap<String, V> {
	private static final long serialVersionUID = 1L;

	@Override
	public V get(Object key) {
		return super.get(((String) key).toUpperCase());
	}

	@Override
	public V put(String key, V value) {
		return super.put(key.toUpperCase(), value);
	}

	@Override
	public void putAll(Map<? extends String, ? extends V> map) {
		Iterator<? extends Entry<? extends String, ? extends V>> iter = map
				.entrySet().iterator();

		while (iter.hasNext()) {
			Entry<? extends String, ? extends V> e = iter.next();
			put(e.getKey(), e.getValue());
		}
	}

	@Override
	public V remove(Object key) {
		return super.remove(((String) key).toUpperCase());
	}

	@Override
	public boolean containsKey(Object key) {
		return super.containsKey(((String) key).toUpperCase());
	}
}
